package com.example.servletdemo.mvc.controller;

import com.alibaba.fastjson.JSON;
import com.example.servletdemo.model.User;
import com.example.servletdemo.mvc.model.Student;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Controller
//@RestController  //Controller+ResposeBody
//@RequestMapping("/test")
public class TestController {
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @Resource
    Student student;


    /**
     * 视图
     * @return
     */
    @RequestMapping("/tests")
    public String tests(){
        return "index";
    }

    /**
     * 视图+value
     * @return
     */
    @RequestMapping(value = {"test2","test22"})
    public String test2(){
        return "index";
    }

    /**
     * method
     * @return
     */
    @RequestMapping(value = "test3",method = RequestMethod.GET)
    public String test3(){
        return "index";
    }

    /**
     * @ResponseBody
     * @return
     */
    @RequestMapping("/testRequestMapping")
    @ResponseBody
    public String testRequestMapping(){
        return "index";
    }

    @RequestMapping("/testName")
    @ResponseBody
    public String testName(@RequestBody String name){
        return "hello:"+name;
    }

    @RequestMapping("/testStudent")
    @ResponseBody
    public Student testStudent(@RequestBody Student student){
        return student;
    }

    @RequestMapping("/testUser")
    @ResponseBody
    public User teest2(@RequestBody User user){
        user.setAdDate2(new Date());
        System.out.println("result:"+JSON.toJSONString(user));
        return user;
    }
}
